<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Session;
use think\Db;
class Config extends Common
{

    public function index()
    {

    }
    public function c_add(){

        $res = Db::table('config') -> where('id',1) -> find();
        $this->assign('res',$res);
        return $this->fetch();
    }
    public function doc_add(){
        $param = Request::instance() -> Param();
        $str = is_base64($param['logo']);
        if($str){
            $image = base64_img($param['logo']);
            if($image['error']){
                $img = $image['msg'];
            }else{
                return(array(
                    'error' => 1,
                    'msg'   => $image['msg']
                ));
            }
            $param['logo'] = $img;
            $old_img = Db::table('config') -> where('id',1) -> find();
            if($old_img['logo']){
                unlink(ROOT_PATH  . 'public'.$old_img['logo']);
            }
        }

        $result = Db::table('config') -> where('id',1) -> update($param);
            if($result){
                //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
                $this->success('编辑成功', 'Config/c_add');
            } else {
                //错误页面的默认跳转页面是返回前一页，通常不需要设置
                $this->error('编辑失败');
            }
        }
}
